<template>
    <!-- 详情 -->
    <div class="messagePer" >
        <el-container class="mesDet">
            <el-header class="mesHead">
                <div class="mesHLe">
                    <div class="mElog">
                        <img class="mElogM" src="@/assets/images/wireai_logo.png" alt="">
                    </div>
                    <div class="mEdes">
                        <div class="mEdesT">
                            {{props.parent.title}}
                        </div>
                    </div>
                </div>
                <div class="mesCZ" >
                    <div class="mesCZ_it" @click="closeDetailModul" >
                        <el-icon size="16"><Close /></el-icon>
                    </div>
                </div>
            </el-header>
            <el-container class="mesDc">
                <el-aside class="mesDAsi" v-loading="loading1">
                    <div class="mesTh">
                        <!--  -->
                        <div class='mesThI'>报价单(<span class="def">{{ listfiler().length }}</span>/{{messageListStore.projectmessagelist.length}})</div>
                        <el-dropdown trigger="click" @command="handleCommand">
                            <div class="mesSele" :class="{ act: menAct != 0 }">
                                {{ menList[menAct].name }} <el-icon style="margin-left: 4px;"><arrow-down /></el-icon>
                            </div>
                            <template #dropdown>
                                <el-dropdown-menu>
                                    <el-dropdown-item  v-for="(item, index) in menList" :command="item.index">
                                    {{ item.name}}</el-dropdown-item>
                                </el-dropdown-menu>
                            </template>
                        </el-dropdown>
                    </div>
                    <div class="mesListB">
                        <ul class="mesDul" >
                            <template v-for="(item,index) in listfiler()" :key="item.id">
                               
                                <li class="mesDli" 
                                :class="{isdu:item.status == 5,act:messageListStore.childAct.id == item.id}" 
                                @click="showDetailDe(item)" >
                                    <div class="dlit" >
                                        <i class="mdot"></i>
                                        <p class="mdotp">{{item.companyname}}</p>
                                    </div>
                                    <div class="mdtime">
                                        {{formatTimeDifference(messageListStore.downTime,item.offertime) }}
                                    </div>
                                </li>
                            </template>
                        </ul>
                    </div>
                </el-aside>
                <el-main class="mesMain" v-loading="loading">
                    <div class="mMt" v-if="detailInfo">
                       <div class="mMt_ar">来自 {{detailInfo.companyname}} 的报价信息</div>
                         <div class="mMt_ot">
                            <div class="mMtI">{{timestampToDatetime(detailInfo.offertime).year}}</div>
                            <div class="mMtI">{{timestampToDatetime(detailInfo.offertime).weekday}}</div>
                            <div class="mMtI">{{timestampToDatetime(detailInfo.offertime).time}}</div>
                        </div> 
                    </div>
                    <div class="mMC" v-if="detailInfo">
                        <div class="mMCH">
                            <div class="mMCpdfs" v-if="detailInfo.file">
                                <div class="mMCpdf" :class="ispdfRE(detailInfo.baojianame)">
                                  {{detailInfo.baojianame}}</div>
                                <!-- <div class="mMCpdflx">
                                    ( <span>5M</span> <span>25天后过期</span> )
                                </div> -->
                            </div>
                            <div class="mMCbts">
                                <div class="mMCdown" v-if="detailInfo.file"  @click.stop="downloadfile()" >下载报价单</div>
                                <div class="mMCyx " v-if="detailInfo.allowstatus==0"  @click="authorContact(detailInfo)">允许企业获得联系方式</div>
								<div class="mMCyx act" v-else >企业已获得联系方式</div>
							</div>
                        </div>
                        <div class="mMDetai">
                            <div class="mMDetai_html" v-html="detailInfo.content"></div>
                        </div>
                    </div>
                </el-main>
            </el-container>
        </el-container>
    </div>

</template>
<script setup lang='ts'>
const imgurl = import.meta.env.VITE_APP_TITLE + '/assets/images/';
import { useUserStore } from "@/store/modules/user";
import { useSystemStore } from "@/store/modules/system";
import { useMessageListStore } from "@/store/modules/messagelist";
import { ArrowDown,Close,FullScreen } from '@element-plus/icons-vue'
import pdfapi from "@/api/pdf.ts"
import {formatTimeDifference,timestampToDatetime,ispdfRE} from "@/utils/timeFun"

const props = defineProps({
    parent:{
        type: Object,
        require: true,
        default: {}
    }
});
const emit = defineEmits(["onCloseModule"]);

const api = inject('$base', null as any);
const baseurl = inject('$baseurl', null as any);
const useStore = useUserStore();
const base = useSystemStore();
const messageListStore = useMessageListStore();
const loading1 = ref<any>(false)
const loading = ref<any>(false)
const isFullscreen = ref(false);
const isClickMeid = ref<any>("");
const isList = ref<any>(0);
const page = ref(1);

const menList = ref([{
    name: "全部",
    index: 0
}, {
    name: "未读",
    index: 1
}, {
    name: '已读',
    index: 2
}])


const menAct = ref<number>(0);//报价单筛选项

/**
 * 查看详情
 */
const detailInfo = ref<any>();
function showDetailDe(item){
    loading.value = true;
    messageListStore.childAct=item;
    pdfapi.projectmessageview({
        id:item.id
    }).then((res)=>{
        console.log(res)
        detailInfo.value = res.data
        loading.value =false;
        initgetmembermessage();
        projectlist();
        clickIndex();
    })
}
//关闭弹出层
function closeDetailModul(){
    emit('onCloseModule',false)
}
/**
 * 报价单筛选
 * @param command 筛选项参数
 */
function handleCommand(command: number) {
    menAct.value = command;
}
/**
 * 允许企业授权联系方式
 */
function authorContact(item){
    if(item.allowstatus == 1)
    {
        return false;
    }
    
    pdfapi.allowcompanyget({
        id:item.id
    }).then((res)=>{
        ElMessage({
            message: '已允许企业授权联系方式',
            type: 'success',
            duration:1000
        })
        showDetailDe(item)
    })
}
/**
 * 关闭消息中心
 */
function closeDetailMudle(){
    isList.value = 0;
    setTimeout(() => {
        base.isMessageType = 0;
    }, 500);
}
/**
 * 全屏放大
 */
function changeFullscreen() {
    isFullscreen.value = !isFullscreen.value
}

function initgetmembermessage(){
    pdfapi.getmembermessage({
        id:useStore.userIds
    }).then((res)=>{
        messageListStore.merberInfoSt = res.data
        console.log(res)
    })
}
function projectlist(){
    const data= {
        userid:useStore.userIds,
        page:page.value
    }
    pdfapi.projectlist(data).then((res)=>{
        console.log(res);
        messageListStore.downTime = res.data.time
        messageListStore.permessageList = res.data.projectlist
    })
}
/**
 * 点击进入详情单页面
 */
 function clickIndex() {

    const data= {
        userid:useStore.userIds,
        page:1,
        projectid:props.parent.id,
        status:0
    }
    pdfapi.projectmessagelist(data).then((res)=>{
        messageListStore.projectmessagelist = res.data.projectmessagelist;
        messageListStore.downTime = res.data.time;
    })
}

function downloadfile(){
    const a = document.createElement("a");
    a.href = baseurl + detailInfo.value.file;
    a.download = detailInfo.value.baojianame.split('.')[0];
    document.body.appendChild(a);
    a.click(); // 点击下载
    document.body.removeChild(a); // 下载完成移除元素
}

function listfiler (){
    
    const data= messageListStore.projectmessagelist;
    let filteredData = [];
    if(menAct.value === 0)
    {
        filteredData = data
    }
    else if(menAct.value ==1)
    {
       filteredData =  data.filter(item => [1, 2, 3, 4].includes(item.status));  
    }
    else
    {
        filteredData =  data.filter(item => [5].includes(item.status)); 
    }
    
    
    console.log(filteredData)
    return filteredData
}


onMounted(() => {
    showDetailDe(messageListStore.childAct);
    console.log()
})

</script>



<style lang="scss" scoped>
.messagePer {
    width: 100%;
    height: 100%;
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
}

.mesBox {
    width: 90%;
    max-width: 1100px;
    height: 80%;
    background: #ffffff;

    box-sizing: border-box;
    border-radius: 10px;
    transition: 0.2s ease;
    flex-direction: column;
    display: flex;
    position: relative;
    .mesMenu{
        display: flex;
        justify-content: flex-start;
        align-items: center;

        position: absolute;
        top: 16px;
        right: 24px;
        .mesMenuBtn{
            width: 26px;
            height: 26px;
            display: flex;
            justify-content: center;
            align-items: center;
            align-content: center;   
            margin-right: 2px;
            cursor: pointer;
            &:last-child{
                margin-right: 0;
            }
            &:hover{
                color: #2379f7
            }
        }
    }
    
}

.fullScreen {
    width: 100%;
    max-width: 100%;
    height: 100%;
    border-radius: 0;
}



.mesHeader {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 45px;
    line-height: 45px;
    padding: 0 20px;
    box-sizing: border-box;

    .mesTit {
        font-size: 18px;
        color: #2379f7;
        font-family: "siyuanM";
    }
}

.mesCon {
    display: flex;
    justify-content: space-between;
    flex: 1;
    height: 0;
    background: #ffffff;
    border-radius: 6px;
    overflow: hidden;

    .mesCLe {
        width: 100%;
        height: 100%;
        transition: 0.3s linear;
        padding: 20px 4px 30px;
        box-sizing: border-box;
        display: flex;
        flex-wrap: nowrap;
        flex-direction: column;

        &.width50 {
            width: 33.33%;
        }

        .mesCLeB {
            flex: 1;
            width: 100%;
            overflow: auto;
            padding: 0 20px;

            .mesCUl {
                width: 100%;

                .mesCLi {
                    display: flex;
                    justify-content: space-between;
                    align-items: center;
                    align-content: center;
                    line-height: 24px;
                    padding: 10px 0;
                    border-bottom: 1px solid #dbe2ee;
                    cursor: pointer;

                    .mesLsL {
                        display: flex;
                        justify-content: flex-start;
                        flex: 1;
                        width: 0;

                        .mesLsLT {
                            width: 100%;
                            font-family: 'siyuanR';

                            box-sizing: border-box;
                            font-weight: normal;
                            position: relative;
                            display: flex;
                            justify-content: flex-start;
                            align-items: center;
                            align-content: center;

                            .meSp {
                                font-size: 15px;
                                color: #010101;
                                display: block;
                                white-space: nowrap;
                                text-overflow: ellipsis;
                                overflow: auto;
                                padding-left: 6px;

                                &::after {
                                    content: '';
                                    width: 2px;
                                    height: 14px;
                                    background: #010101;
                                    position: absolute;
                                    left: 0;
                                    top: 50%;
                                    transform: translate(0, -50%)
                                }

                            }

                            .meSpi {
                                margin-left: 8px;
                                min-width: 16px;
                                height: 16px;
                                line-height: 16px;
                                text-align: center;
                                background: #fb6e76;
                                font-size: 12px;
                                color: #ffffff;
                                border-radius: 15px;
                                padding: 0 5px;
                                display: inline-block;
                                font-style: normal;
                            }
                        }
                    }

                    .mesLsR {
                        display: flex;
                        justify-content: space-between;
                        align-items: center;
                        align-content: center;
                        margin-left: 20px;

                        .mesIc {
                            margin-right: 10px;

                            .mesBj {
                                padding: 0 10px;
                                height: 22px;
                                line-height: 22px;
                                font-size: 12px;
                                font-family: 'siyuanR';
                                border-radius: 10px;

                                &.ybj {
                                    background: #e8f1fe;
                                    color: #2379f7;
                                }

                                &.wbj {
                                    background: #f1f5fb;
                                    color: #9094b0;
                                }
                            }
                        }

                        .mesTime {
                            font-size: 12px;
                            color: #9094b0;
                        }
                    }

                    &:hover,&.act {
                        .mesLsL {
                            .mesLsLT {
                                .meSp {
                                    color: #2379f7;
                                    &:after{
                                        background:#2379f7;
                                    }
                                }
                            }
                        }
                    }

                }
            }
        }


    }

    .mesCri {
        width: 0;
        flex: 1;
        display: flex;
        justify-content: flex-start;

        .mesCLB {
            flex: 1;
            width: 0;
            height: 100%;
            background: #ffffff;
            padding: 20px 4px 30px;
            display: flex;
            flex-direction: column;

            .mlbUlB {
                width: 100%;
                overflow: auto;
                flex: 1;
                padding: 0 6px;
                box-sizing: border-box;

                .mlbUl {
                    .mlbLi {
                        width: 100%;
                        display: flex;
                        justify-content: space-between;
                        align-items: center;
                        padding: 0 5px;
                        box-sizing: border-box;
                        cursor: pointer;

                        .mname {
                            font-size: 15px;
                            color: #010101;
                            font-family: 'siyuanM';
                            white-space: nowrap;
                            overflow: hidden;
                            text-overflow: ellipsis;
                            margin: 0;
                        }

                        .mtime {
                            font-size: 12px;
                            color: #9094b0;
                            font-family: 'siyuanR';
                            white-space: nowrap;
                            margin-left: 6px;

                        }

                        &:hover ,&.act{
                            background: #f0f7fe;
                            color: #777777;
                            .mname{
                                color: #2379f7;
                               
                            }
                        }
                    }

                }
            }



        }

        .mesCRB {
            width: 50%;
            height: 100%;
            background: #ffffff;
            padding: 20px 4px 30px;
            box-sizing: border-box;
            display: flex;
            flex-direction: column;

            .mesCRBC {
                display: flex;
                justify-content: center;
                align-items: flex-start;
                align-content: flex-start;
                flex-wrap: wrap;
                padding: 0 6px;

                .mesPre {
                    width: 100%;

                    .mesPreImg {
                        width: 100%;
                        display: block;
                    }
                }

                .mesPreBtns {
                    width: 100%;
                    padding: 0 30px;
                    box-sizing: border-box;

                    .mesPreBtn {
                        width: 125px;
                        height: 32px;
                        background: #2379f7;
                        color: #fcfdfe;
                        opacity: 1;
                        border-radius: 5px;
                        text-align: center;
                        line-height: 32px;
                        cursor: pointer;

                        &:hover {
                            opacity: 0.7
                        }
                    }
                }
            }



        }
    }
}

.noMore {
    .noImg{
        background: url('../../assets/miscel/none.png') center center;
        background-size: 97px 97px;
        width: 97px;
        height: 97px;
        margin: 0 auto;
    }
    .noMoreP {
        font-size: 14px;
        text-align: center;
        color: #9094b0;
        width: 100%;
        text-align: center;
        line-height: 30px;
    }
}

.slideOpen .mesCLe {
    border-right: 1px solid #dbe2ee;
    background: #fcfcfd;
}

.slideOpen .mesCLeB {
    padding-right: 6px !important;
}

.slideOpen .mesCLB {
    border-right: 1px solid #dbe2ee;
}








.mesDet {
    width: 100%;
    height: 100%;
    display: flex;
    background: #ffffff;
    
    .mesHead {
        display: flex;
        justify-content: space-between;
        align-items: center;
        align-content: center;
        border-bottom: 1px solid #dbe2ee;

        .mesHLe {
            display: flex;
            justify-content: flex-start;
            align-items: center;
			width: 100%;
            .mElog {
                margin-right: 15px;

                .mElogM {
                    height: 30px;
                    display: block;
                }
            }

            .mEdes {
                    height: 30px;
                    line-height: 30px;
                    font-size: 14px;
                    font-family: 'siyuanR';
                    position: relative;
                    padding-left: 15px;
					flex: 1;
					width: 0;
                    &::after{
                        content: '';
                        width: 2px;
                        height: 16px;
                        background: #9094b0;
                        position: absolute;
                        left: 0;
                        top: 50%;
                        transform: translate(0,-50%)
                    }
                    .mEdesT {
                        color: #9094b0;
						white-space: nowrap;
						overflow: hidden;
						text-overflow: ellipsis;
						
                    }
                    .mEdesA{
                        color: #000;
                    }
                }

        }
        .mesCZ{
            display: flex;
            justify-content: flex-start;
            align-items: center;
            align-content: center;
            .mesCZ_it{
                width: 24px;
                height: 24px;
                margin-right: 16px;
                margin-right: 5px;
                display: flex;
                justify-content: center;
                align-items: center;
                align-content: center;
                cursor: pointer;
                &:last-child{
                    margin-right: 0;
                }
                &:hover{
                    color: #2379f7;
                }
            }
        }
        

    }


    .mesDc {
        background: #fcfcfd;
        height: 0;

        .mesDAsi {
            padding: 20px 20px;
            box-sizing: border-box;
            border-right: 1px solid #dbe2ee;
            display: flex;
            flex-direction: column;
            flex-wrap: wrap;
			width: 35%;
			max-width: 400px;
            .mesTh {
                width: 100%;
                display: flex;
                justify-content: space-between;
                align-items: center;
                align-content: center;
                padding-bottom: 10px;

                .mesThI {
                    font-size: 13px;
                    line-height: 28px;
                    color: #666666;
                    font-family: 'siyuanN';

                    .def {
                        color: #000000;
                    }
                }

                .mesSele {
                    width: 60px;
                    height: 28px;
                    background: #e5ebf6;
                    color: #666666;
                    font-size: 13px;
                    display: flex;
                    justify-content: center;
                    align-items: center;
                    align-content: center;
                    border-radius: 4px;

                    &.act {
                        color: #2379f7
                    }
                }
            }

            .mesListB {
                width: 100%;
                flex: 1;
				height: 0;
                .mesDul {
                    overflow: auto;

                    .mesDli {
                        height: 50px;
                        display: flex;
                        justify-content: space-between;
                        align-items: center;
                        align-content: center;
                        padding: 0 6px 0 6px;
                        background: #ffffff;
                        border-radius: 4px;
                        cursor: pointer;

                        .dlit {
                            flex: 1;
                            width: 0;
                            display: flex;
                            justify-content: flex-start;
                            align-items: center;

                            .mdot {

                                display: block;
                                position: relative;
                                width: 10px;
                                height: 20px;
                                margin-right: 6px;

                                &::after {
                                    width: 6px;
                                    height: 6px;
                                    background: #2379f7;
                                    border-radius: 50%;
                                    content: '';
                                    position: absolute;
                                    top: 50%;
                                    left: 50%;
                                    transform: translate(-50%, -50%)
                                }
                            }

                            .mdotp {
                                flex: 1;
                                width: 0;
                                font-size: 15px;
                                font-family: 'siyuanN';
                                line-height: 20px;
                                margin: 0;
                                white-space: nowrap;
                                text-overflow: ellipsis;
                                overflow: hidden;
                            }
                        }

                        .mdtime {
                            font-size: 13px;
                            font-family: 'siyuanR';
                            color: #9094b0;
                            margin-left: 10px;
                        }
                        &.isdu{
                            .dlit {
                                .mdot {
                                   display: none;
                                }
                                .mdotp {
                                    color: #666666;
                                    font-family: 'siyuanN';
                                }
                            }
                        }
                        &:hover,
                        &.act {
                            background: #f0f7fe;

                            .dlit {
                                .mdotp {
                                    color: #2379f7;
                                    font-family: 'siyuanN';
                                }
                            }

                            .mdtime {
                                color: #777777
                            }
                        }
                    }

                }

            }

        }


        .mesMain {
            padding: 40px 40px 20px;
            display:flex;
            flex-direction:column;
            .mMt{
                padding-bottom: 14px;
                .mMt_ar{
                    font-size: 20px;
                    color: #2379f7;
                    font-family: 'siyuanM';
                    line-height: 30px;
                }
                .mMt_ot {
                    display: flex;
                    justify-content: flex-start;
                    align-items: center;
                    height: 26px;
					
                    .mMtI {
                        font-size: 12px;
                        color: #9094b0;
                        font-family: 'siyuanM';
                        margin-right: 10px;
                        margin-top: 6px;
                        &:last-child{
                            margin-right: 0;
                        }
                    }
                }
               
            }

            .mMC {
                width: 100%;
                border: 1px solid #dbe2ee;
                background: #ffffff;
                padding: 30px 30px;
                flex:1;
               
              
                .mMCH {
                    display: flex;
                    justify-content: flex-start;
                    align-items: center;
                    flex-wrap: wrap;
                    border-bottom: 1px solid #dbe2ee;
                    .mMCpdfs {
                        background: #f0f7fe;
                        display: flex;
                        justify-content: flex-start;
                        align-items: center;
                        padding: 0 8px;
                        line-height: 30px;
                        box-sizing: border-box;
                        margin-right: 40px;
                        margin-bottom: 15px;
                        .mMCpdf {
                            font-size: 14px;
                            color: #333333;
                            &.pdf{
                                background: url('../../assets/images/icon2.png') no-repeat left center ;
                                background-size: 16px auto;
                                padding-left: 20px;
                            }
                            &.doc{
                                background: url('../../assets/images/icon1.png') no-repeat left center ;
                                background-size: 16px auto;
                                padding-left: 20px;
                            }
							&.xls{
							    background: url('../../assets/images/icon99.png?v=100') no-repeat left center ;
							    background-size: 16px auto;
							    padding-left: 20px;
							}
							&.ppt{
							    background: url('../../assets/images/icon98.png?v=100') no-repeat left center ;
							    background-size: 16px auto;
							    padding-left: 20px;
							}
                            &.other{
                                background: url('../../assets/images/link.png') no-repeat left center ;
                                background-size: 16px auto;
                                padding-left: 20px;
                            }
                            
                        }
                        .mMCpdflx{
                            margin-left: 10px;
                            font-size: 13px;
                            color: #9094b0;
                            span{
                                margin-right: 6px
                            }
                        }
                    }
                    .mMCbts {
                        display: flex;
                        justify-content: flex-start;
                        margin-bottom: 15px;
                        .mMCdown {
                            padding: 0 20px;
                            height: 30px;
                            text-align: center;
                            line-height: 30px;
                            background: #2379f7;
                            color: #ffffff;
                            border-radius: 6px;
                            cursor: pointer;
                            white-space:nowrap ;
							font-size: 14px;
							margin-bottom: 6px;
                            &:active{
                                opacity: 0.7
                            }
                            margin-right: 20px;
                        }
                        .mMCyx{
                            padding: 0 20px;
                            height: 30px;
                            text-align: center;
                            line-height: 30px;
                            background: #e8f1ff;
                            color: #2379f7;
                            border-radius: 6px;
                            cursor: pointer;
							font-size: 14px;

                            &.act{
                                background: #409eff;
                                color: #ffffff;
                            }

                            &:active{
                                opacity: 0.7
                            }
                        }
                    } 
                }
                .mMDetai {
                    padding: 15px 0;
                    box-sizing: border-box;
                    width: 100%;
                    min-height: 200px;
					.mMDetai_html{
						font-size: 14px;
					} 
                 }
            }
        }
    }
}


@media screen and (max-width: 768px){
	.mesDet .mesHead .mesHLe .mElog .mElogM{
		height: 24px;
	}
	.mEdesT{
		font-size: 12px;
	}
	.mesDAsi{
		display: none!important;
	}
	.mesDet .mesDc .mesMain{
		padding: 20px 10px 20px;
	}
	.mesDet .mesDc .mesMain .mMC{
		padding:20px 10px;
	}
	.mesDet .mesDc .mesMain .mMt .mMt_ar{
		font-size: 16px;
		line-height: 24px;
	}
	.mesDet .mesDc .mesMain .mMC .mMCH .mMCbts .mMCyx{
		font-size: 12px;
	}
	.mesDet .mesDc .mesMain .mMC .mMCH .mMCbts .mMCdown{
		font-size: 12px;
	}
}

</style>